{extend name="layout/iframe" /}

{block name="content"}
<div class="x-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="globalName" class="layui-form-label">
                <span class="x-red">*</span>商圈名称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="globalName" name="globalName" lay-verify="globalName" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="col-md-6">
                <div class="row selectCon">
                    <div class="layui-form-item" id="x-city">
                        <label class="layui-form-label">商圈地址</label>
                        <div class="layui-input-inline">
                            <select name="province" id="province" class="areaLists" lay-filter="province">
                                <option value="">请选择省</option>
                            </select>
                        </div>
                        <div class="layui-input-inline">
                            <select name="city" id="city" class="areaLists" lay-filter="city">
                                <option value="">请选择市</option>
                            </select>
                        </div>
                        <div class="layui-input-inline">
                            <select name="area" id="district" class="areaLists" lay-filter="area">
                                <option value="">请选择县/区</option>
                            </select>
                        </div>
                    </div>
                </div>
                <br />
                <div class="add-more " style="margin-top: 0">
                    <div class="layui-input-inline" style="width:600px;margin-left: 10%;">
                        <input type="text" id="address" name="input_address" lay-verify="input_address" autocomplete="off" class="layui-input" placeholder="请输入详细地址">
                        <input id="addtxt" type="hidden" />
                        <input type="hidden" id="add-text1" value="" class="form-control input-large" style="position: relative;top: 300px;left: 0px;z-index: 1;" name="addressGeo">
                        <div style="width:100%;height:300px;" id="map_container"></div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <button  class="layui-btn" lay-filter="add" lay-submit="">增加</button>
        </div>
    </form>

    <script type="text/javascript" src="__STATIC__/admin/js/xcity.js?v={:time()}"></script>
    <script src="https://api.map.baidu.com/api?v=2.0&ak=07E2669c3b77a0793274952ba61cd8b8&s=1" type="text/javascript"></script>
    <script type="text/javascript" src="__STATIC__/admin/js/baidumap.js?v={:time()}"></script>
    <script>

        layui.use(['form','code'], function(){
            form = layui.form;
            layui.code();
            $('#x-city').xcity('湖北','武汉市','洪山区');
        });

        layui.use(['form','layer'], function(){
            $ = layui.jquery;
            var form = layui.form
                ,layer = layui.layer;

            //自定义验证规则
            form.verify({
                globalName: function(value){
                    if(value == ''){
                        return '商圈名称不能为空';
                    }
                }
                ,input_address: function(value){
                    if(value == ''){
                        return '地址不能为空';
                    }
                }
                ,addressGeo:function (value) {
                    if(value == ''){
                        return '没有获取到经纬度';
                    }
                }
//            ,pass: [/(.+){6,12}$/, '密码必须6到12位']
//            ,repass: function(value){
//                if($('#L_pass').val()!=$('#L_repass').val()){
//                    return '两次密码不一致';
//                }
//            }
            });

            //监听提交
            form.on('submit(add)', function(data){
                console.log(data);
                //发异步，把数据提交给php
                $.ajax({
                    url:"{:url('Businessarea/addoreditpost')}",
                    data:data.field,
                    type:"Post",
                    dataType:"json",
                    success:function(data){
                        layer.msg(data.msg);
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                    },
                    error:function(data){
                        layer.msg("pppp");
                    }
                });

                return false;
            });
        });
    </script>
</div>
{/block}